package csdn;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class ScriptEngineDemo {
	
	private static ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
	
	public static void main(String[] args) throws ScriptException{
		
		System.out.println(getResult("1+2*4-2"));
	}
	
	private static double getResult(String str) throws ScriptException{
		return (Double)engine.eval(str);
	}
}